package com.salt.security.wechat.auth;

import com.salt.security.BaseUserDetails;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AbstractAuthenticationToken;

/**
 * 自定义微信jsCode换取token
 *
 * @author HaiBo Kuang
 * @date 2021/4/20 20:49
 */
public class JsCodeAuthenticationToken extends AbstractAuthenticationToken {
    private final Logger logger = LoggerFactory.getLogger("Js_Code_token");
    private final String jsCode;
    /**
     * 用户基础信息
     */
    private BaseUserDetails userDetails;
    /**
     * 用户 openId
     */
    private String openId;
    /**
     * 是否绑定
     */
    private Boolean weChatBind;

    /**
     * Creates a token with the supplied array of authorities.
     */
    public JsCodeAuthenticationToken(String jsCode) {
        super(null);
        this.jsCode = jsCode;
    }

    /**
     * 获取认证凭证
     *
     * @return 认证凭证
     */
    @Override
    public Object getCredentials() {
        // jsCode为身份验证凭证
        return this.jsCode;
    }

    /**
     * 获取身份验证主体。
     *
     * @return 身份验证主体
     */
    @Override
    public Object getPrincipal() {
        return null;
    }


    public BaseUserDetails getUserDetails() {
        return userDetails;
    }

    public void setUserDetails(BaseUserDetails userDetails) {
        this.userDetails = userDetails;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public Boolean getWeChatBind() {
        return weChatBind;
    }

    public void setWeChatBind(Boolean weChatBind) {
        this.weChatBind = weChatBind;
    }
}
